implementing file writing