Minor optimisation made

Method for writing file added