Added File writing function