Try making sure directory exists before writing file