File creation and editing in Ignition

Are you aware that using perspective or webdev, the docx file must be accessible and writable by the gateway service because the python scripts invoked by perspective or webdev are executed in the gateway or perspective scope?

It might be possible to install the python-docx package in Jython and make it available to Ignition. There is a forum thread here which might give you some hints: Procedure for installing python libraries from source
Also this article: https://support.inductiveautomation.com/hc/en-us/articles/360056397252-Python-In-Ignition