They "mark" their territory this way.
Dogs sniff to find out who else has marked the territory, before leaving.
Scent marking is an instinctual behavior in which a dog deposits his own odor in the form of urine or feces onto his environment to mark territory or make a statement.