Cats are funny aren't they with all their little mannerisms. I have never had a cat do that, but yes I did see it online. I used to mostly encourage my cats to go outside when they needed to go, we had a cat door for them to get in and out, however at night time I would put out litter and keep them inside. I never had one that would perch on the side of the litter box. That being said you can teach cats to do certain things, it just takes time and patience and it is a lot more difficult than training a dog.
For example my cat used to catch a lot of mice and insisted on playing with them, letting them go and catching them again, however sometime he really let the mouse go. I did not want that so I began to take the mouse away from my cat and killed the mouse myself and disposing it in the garbage, he did not take long to learn that if he was not going to kill or eat the mouse, he would lose it. It worked, he started eating them. We lived on a farm and there were mice everywhere, and the last place I wanted them was in the house so it was a little game between us for a few weeks. But he was excellent at catching them, if one was stupid enough to come out from behind the stove or fridge where they hid, my cat never missed.