Why my dog poops all soft like diarrhea every time?

Hey there, can anyone explain to me why is it that my dog poops all soft like he’s got diarrea everytime I take him for a walk but he poops fine (firm and healthy) at home? It doesn’t seem like he’s sick because his poop is normal at home but it’s really weird. He’s very active and playful, eats well and has lots of exercise but he’s very anxious (he’s a rescue, was abandoned as a pup). I think it has to do with his anxiety at being out, trauma and fear of being abandoned again but he loves going out for a walk (I take him out every morning when I go to the bakery, it’s a 6km walk). Is there anything I can do about it? It’s a pain in the ass trying to scoop soft wet poop from the sidewalk.