Simple question about writing to files

You should either use:
FunctionSpace.tabulate_dof_coordinates() which has a one to one correspondence with

Or you can interpolate the function values into the mesh coordinate space by using
compute_vertex_values() as shown in