tests: switch from tmpnam to mkstemp

Use mkstemp to generate a temporary file in a safer way than tmpnam,
and placed in the temporary home created for the tests already.