Fixed temporary file writing code.