Ensure extension is correct when creating temporary file
(cherry picked from commit 1548ea1e7e0d8f8411c43c8dcb07f22066d22c2f)