Apparently some psychologists think it's to do with our recent (evolutionarily) choice to not poop outdoors. So people like to be seen picking up after their dogs, but exhibit it in the open when they think nobody is looking as a proxy for pooping outdoors.