Use mkstemp instead of deprecated tmpnam.