Replace the tempname() function call with mkstemp().