Close all output files explicitly

This is an attempt to fix issue 79, in which files sent through gzip
are written incompletely.