make sure the directory is created before writing contents into it