TST: be more aggressive in cleanup of temp files + use mktemp instead of mkstemp