Dynamics 365 F&O cloud version does not runs on your domain/network. It runs on the Microsoft infra (SAAS) and that is why every D365FO system link/address ends with operations.dynamics.com
If you are asking for saving the document on the domain where Dynamics is hosted, you already kind of do that, when you save an attachment, in Dynamics, it already goes to a Storage Account which is hosted on the Microsoft owned Domain/Network(operations.dynamics.com)
I believe, you want to save a document from Dynamics to your/office domain/network which is not operations.dynamics.com?
If my assumption is correct you can do this in many ways.
1) Your X++ code in D365 F&O could upload the generated file to the Azure File Share The on-premises agent(Azure File Sync agent.) would monitor the Azure File Share for new files and, upon detection, move or copy the file to your desired network shared folder.
2) another solution could be using on-prem On-Premises Data Gateway using Power Automate.
3) some SFTP clients can also do this, you can connect them to the Azure Blob storage (the place where Dynamics would drop your file)
4) another solution could be uploading your file to OneDrive for business(using C#) and OneDrive for business can auto-synch the files to any servers of your local network (wherever you install it), X++/Dynamics can call the C#