Close files and rename temp files