Fixed bug while writing to non-existent directory