Fix: Check output file isn't dir, fix tests (Fixes #1034)
Merge pull request #1038 from jrajav/output-file-dir-check

Fix: Check output file isn't already a directory, handle errors, fix and add tests