temp path unsafe due to timing issues in multithreaded use; added threadID to make path unique. mkstemp() probably a better choice in the long run