Added func writeFile with test