Use os.tmpdir() on OS X
Consolidate redundant code