explicitly close() all output files

I think this was causing test failures on pypy, where maybe I can't rely
on an implicit close-on-deref.