fileData starts with an XML signature for UTF-16, but you're writing UTF-8 data!  UTF-8 is fine (and probably preferred, actually), but you should change the header to correctly match what you're writing.