Fix bug in file creation by creating all the directories if needed