Fix race condition with tempfile being cleaned up too soon (hopefully).