mktemp and tmpnam generate predictable names vulnerable to symlink and race attacks.
Use mkstemp which atomically creates and opens a unique file.