I am wondering why you are not using old school method of writing the data to file using a few print statements of your own!
This may cost you a few extra lines of code, but you will be able to write the file the way you wish!
Sorry if this sounds too naive, or doesn't fit your requirement.