new routine to write 2D file