Why do cats knock things off tables?
Mostly curiosity, play and attention. Batting at objects is hunting practice, and cats quickly learn that a falling mug makes their human come running.
Going deeper
Cats are predators, and pawing at a small object to see if it moves is the same instinct they'd use on a mouse. Something that falls, rolls and clatters is a very satisfying result.
There's also a social reason. If knocking a pen off the desk gets you to look up, talk or get out of your chair, the cat has learned a reliable way to get your attention, and it will use it again.