A long shot but worth tryin.
Check your earth strap coming off the battery.
These can get loose sometimes if battery mounting points were removed and left off.
Or a smaller battery put in.

Other than that.

Might be the abs hall sensor on right or left rear wheels.
Can't remember which side.
Used to happen to me on a '98 E39 I had.
I would cycle on an off the key,(while moving). Problem solved for a while.
Never did fix it. Car got sold on eventually. Owner was aware of the gremlin.
Be no harm to plug it in James.