create directory before writing files