secure tempdir creation and deletion, fixes race condition