Make sure output directory exists before writing output