Create containing directory before writing to file