Use mkstemp rather than higher-level interfaces

Should close #2.