fixes #7370 - accept dir output path for rake task, try harder to find output dir

The OUTPUT env var can now be a directory or file.  When not specified, it
will prefer the cwd if it's writable and use tmp otherwise.