Close files after writing to them