Use tempfile module to create a temporary file

Temporary directory in Windows is not a /tmp, use tempfile module