Try to create the directory before writing gitignore.