Judd Apatow, actually, with Bob Odenkerk. Saturday Night Live had the two of them as writers back in 1986, when Shatner did a guest-host appearance.
The sketch is famous because Shatner yells at a bunch of Trekkies for being such losers: “Move out of your parents’ basement!” and “You, you must be almost 30… have you ever kissed a girl?” As we know, Apatow would do a lot more about losers later on.
BONUS: Wikipedia has an entry for the Get a Life by Nadine Gordimer but not the one by William Shatner. I would never, ever have predicted that.
Source: Get a Life by William Shatner, with Chris Kreski