Sounds a bit like XTypedElement wasn't closing the file handle off maybe?
You may have a problem because you've set the append to true:
"Determines whether data is to be appended to the file. If the file exists and
append is false, the file is overwritten. If the file exists and
append is true, the data is appended to the file. Otherwise, a new file is created."
This would create a nonsense xml file if the file already exists. May you should set it to false?