File writing fails when output directory is nonexistent