The reason for that was that on my machine the temporary file had been deleted from the Templfile class destructor before it could have been copied to the freshly launched GCE instance.
I'll change the function to return the reference to the Tempfile instance instead, that way the file won't be deleted and no vulnerability will be introduced.