Its a poor photo, but is this an extra wire that has been connected into the alternator brush gear for an auxiliary alternator controller?
Better than leaving it wagging but there are better and tidier ways.
I am fairly sure that this a temperature sender. Yes, fixing it to the case is good but the cable tie isn’t the best way. Some fit it on the negative post, but better to mount on an existing bolt - either by the diode pack or field coils.
It’s purpose is to turn down a smart alternator controller thats boosting the alternator, looks like sterling, before the alternator fries. It may not work so effectively where it is.