Make sure to create the output directory if it does not yet exist.