Write to opts['outputdir'] if this option has been set.
Minor changes to names, syntax, comments, etc.
Add an option "outputdir", the directory to which output should be written.
Write output to a directory opts['outputdir'], if that option has been set.