Added functionality to write to temporary file