Close tmpfile before rename