Fixed issue with writing to temporary file