changed tempfile.mkstemp() call to tempfile.NamedTemporaryFile(delete=False)