This could be a few things but you need to start with having the computer scanned for trouble codes. This could be an issue with fuel delivery or a sensor. Use this link to find a good shop near you.
https://repairpal.com/repair-shops
Alex
RepairPal Certified shops can diagnose and repair your 2006 BMW 525xi. They provide transparent pricing with a minimum 12-month or 12,000-mile warranty on repairs and services.