flushing the output stream before closing. strangely not everything is written to file otherwise.