It's a capacitive screen much like the touch screens on cell phones.
The first thing to do is rule out 3rd party apps/software/drivers that could be causing it. Boot into Safe Mode (Hold ⇧ Shift
while booting). If the problem stops, then it's a 3rd party app. Start investigating things like:
Login items (System Settings → Users & Groups → Login Items). Disable each one. See if the problem goes away. Yes? Re-enable each one individually and test/observe if the problem comes back. Repeat until you've found the item causing the problem.
Issue the command
sudo launchctl list | grep -v apple. This will list any LaunchAgents or LaunchDameons that are running excluding anything that has "apple" in the name (i.e.
com.apple.coreduetd) which are native Apple daemons.
Create another User account and see if the problem exists there. If so, it's definitely system wide.
You can also try resetting the Touchbar by killing it's processes:
$ pkill "Touch Bar agent";
$ killall "ControlStrip";
If the problem returns, it's definitely hardware.
However, from experience, it's most likely it's due to a physical problem with the touch screen itself. Unfortunately, it means it has to be replaced.