close tempfile after commiting and replacing