Joannesalfa
This code is an example of how to check distance between each instance to find the closest one for each of them.
So printing any distance in a text object doesn't make any sense.
closestInstance.capx
That's what you can use it for.
You can also use the dist variable which is just the distance between the current and the closest. And it is used during the loop to get to the closest one.
Answering the question "How can I check distance between 2 instances?" is closely tied to what you want to use this comparison for. So I had to provide such case as an illustration.
(also you made a mistake, when I write "!=" it means "not equal to")