make tmp dir in TMPDIR not CWD and improve withTempDirectory