Makes sure output directories are created before trying to write to file.