Make sure that the outputdirectory exists before we try to write to it, and add a main() method to allow this to be executed via a shell