Write to tempfile