I've always figured the "shut your engine off for safety while fueling " is an old wives tale at best rooted with cars that were replacing horses more so than anything made in the last 50 years... never seen anyone articulate a valid reason why it is dangerous to run the engine while fueling. Hell, look at Nascar (not that I'm a fan, just saying), half the time they are dumping a gallon of fuel down the side of the car with the engine running and exhaust a lot hotter than ours; I don't think they've killed anyone yet.
I still shut my engine off. I guess I'm a slave to "common sense wisdom". (Full disclosure I let it run when I was working in Winnipeg for a few months and was fueling in ~0F weather. I lived to tell about it)
My buddy in NJ says they aren't allowed to fuel their own cars because that is a "safety issue".
(I've never done independent research on whether NJ residents are smart enough to use a gas pump)
But yeah, if it is only a rough idle with the gas cap off, that is your answer. My brother has had to replace the gas cap TWICE in his DD 2004 3 series due to CELs from it leaking and messing up its pressure function.