Fix temporary file handling to avoid it being deleted too soon.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>