Slight reordering during QuakeML writing.

Assures that no empty file gets written if the validation fails. Also
passed open files will now remain open. The function only closes file
handlers it also opened.