How to save solution in .txt format?

If you are using a scalar space, simply look at:

the $i$th entry in dof_coordinates corresponds to the coordinate of the $i$th degree of freedom, which is the $i$th entry of u.vector().get_local()