Fix: Check output file isn't dir, fix tests (Fixes #1034)