Thanks for your latest reply and continued support.
As you suspected, I am using CreateDocxFromTemplate() to create the DOCX file and createDocxAndDownload() to deliver the document immediately for download. I do not need or desire to save the documents on the server.
To answer your first question. The generated DOCX file is being saved in the webroot.
Here's the runtime error message logged on production:
Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in Phpdocx\Utilities\DOCXStructure->saveDocx()
When the "permission denied" error occurs on production, the download DOCX file is completely empty.
To answer your next question, sys_get_temp_dir() returns "/tmp" both locally and production. However, Acquia prevents the usage of "/tmp" and instead says to use "/mnt/tmp/[sitename].[env]".
https://docs.acquia.com/acquia-cloud/manage/files/temporary/
Acquia is the biggest Drupal hosting service around so compatbility with their environment is essential.
I would prefer not to mess with php.ini.
Ideally, I would like to use a custom directory as the temporary directory. In Drupal this is commonly "sites/default/files".
Again, I tried assigning "temp_path" the absolute server path to the "files" directory, but the setting is seemingly ignored by CreateDocxFromTemplate().
That said, what do you recommend to resolve this "permission denied" and temporary directory issue?