Long ago I had a similar issue. The cause was an exception-error in the IDE.
If the code that generates the XML fails with an unexpected exception (E.g. overflow/range-check/nil-deref) then the IDE may report that as write error (its while trying (preparing) to write). That would leave the file empty.
So the question is, what in your session causes this error.
Ideally run your IDE in the debugger. If not get log output with trace.
Either way, first thing you would need is to ensure your IDE is compiled with debug info:
Menu: Tools > Configure build Lazarus
On the dialog, in the input for "Custom options" ensure you have: -O-1 -gl -gw3
(add at the end, and keep whatever else is in there)
=> re-build the IDE (unless you already had those)
1) Debug:
Run the IDE, open ide/lazarus.lpi => press F9
Then in the 2nd IDE get the error
When the error happen get the stacktrace and other info from the 1st IDE.
2) Open IDE with --debug-log=somefile.txt
get the error, attach the log