Word uses a closed proprietary format so tryng to create Word docs from your own code is always going to be a tough battle. If you're running on a Windows, server, this may be easier using specialist dll's, I'm not sure - I tend to avoid Windows as far as possible.
Your original intention was to "simulate my output in a text document that can be saved and edited if required" so why not do just that? Use plain text format? You can easily use PHP to send HTTP headers to tell your browser that the coming file is text file so that it opens notepad or kate or whatever your preferred text editor is.
If you need more formatting than that, try searching for libraries to create open format documents in Rich Text Format - RTF. Word can read/write these, and as the format is open, it should be easier to find solid libraries.