New temporary directory logic and a fix for depending on HOME being set