For a week or so now I have been noticing a problem when driving that most occurs when going down hills where I can feel the car bucking or surging. I also noticed that sometimes it would idle at about 1,100 rpm instead of the usual 700-800 rpm.
I started noticing that the fuel consumption gauge was showing a reading above zero when the car was moving in gear but I wasn't touching the throttle, where usually it should read zero.
It turns out the car was randomly accelerating a little on its own.
I checked for fault codes but there were none reported and tried cleaning the throttle body in case it wasn't fully closing, but that didn't help the problem.
I asked on the BMW M42 / BMW M44 Facebook group for suggestions on what the problem might be and got a few responses including somebody who had experienced the same issue and found the cause was the wiring to the throttle position sensor (TPS).
I checked the wiring to mine and it looked okay but I unplugged and plugged the connector back in several times to make sure the connection was good, and amazingly that solved the problem.