GetComponent<> gets a component of the given type from the current gameObject. If you want set the textmesh of a different gameobject, you would need to have a reference to it first.
The easiest way to solve this, is to create a public TextMesh variable and then drag the object into the inspector field that is created for that variable. Then in the script you just do “variablename.text = …”
Another way would be to find the correct gameobject first using one of the find functions, or by also creating a public variable for that. And then do GetComponent on that gameobject.