You do not say what model X3 you have. I drive a 2005 E83 X3 2l diesel and the intake pipe leading to the egr has a sensor in the pipe which is quite easy to remove and clean with carb cleaner. When i got my car secondhand it had a very bad flat spot. It was really bad but i got the car for a song, so knew i had to do some work on it to get it to run smoothly. What i did was to clean the egr, air flow meter, boost pipe sensor (i think some people call it the intake temp sensor???) and removed and plugged the swirl flaps on the inlet manifold (a big must if you drive a diesel!!). Car ran like a dream after doing this so not sure what was the cure but has been going very nicely now for about 30k kms and eighteen months. To remove the pipe i think you give it a quarter turn anti clockwise and remove or some need a nineteen (??) socket to remove.