Use mkstemp instead of mktemp.