Create directory before trying to write.