What object are you sending the "Generate Python Code" message to, when the user clicks on the Journal button?
It should be a valid Formula Depot reference. My guess is that the message is being sent to another type of object, and being ignored.
Then the variable holding what would be the Python code is empty, which results in an error when trying to save it to a text file.
So another thing you can try is to add a 'Show(py_code)' statement to your code. Always double-check the content of your variables!
I would also suggest working on this with tech support, as you will be able to share your code, data, etc.
That will help a lot with figuring out what is going on.