Fixes #2 tmpfile can get deleted before curl executes on it.

Delays the closing of the tempfile until after the curl_exec.