Letterman invited Bill O'Reilly to his show
It's not clear to me that Letterman invited O'Reilly on, per se. There are many more/larger entities at work than just Letterman's personal desires. It's very possible that Les Moonves wanted it to happen or any other corporate heavyweight.
Even though Letterman is a heavyweight, it's obvious that he doesn't pick and choose every single guest. He's made it clear in the past that he's not thrilled about being a 'commercial' for every single Hollywood Star, New TV show and new movie that comes out. But that's part of the deal. So I wouldn't necessarily assume that Letterman ever said "Hey! Let's get O'Reilly on the show!"
and it's not like he doesn't know that Letterman is a liberal?
I'm not sure that *I* know that Letterman is a liberal, even now. As somebody who has watched Letterman from the 80s until today (much less freuently today), it wasn't until the O'Reilly show that I ever saw Dave take a specifically slanted persepective one way or the other. Dave has been supportive of the war and of Bush's policies. Dave has been openly supportive of Rush Limbaugh. He's certainly no left-wing mouthpiece.
And, even on the O'Reilly episode, I don't leave there thinking "Damn, Letterman sure is some left-wing extremist". Letterman's biggest beef with O'Reilly was in regards to human compassion about Sheehan and the fact that she lost her son and the fact that O'Reilly (seemingly) has no sympathy for her whatsoever. That's not a left-wing-liberal perspective. That's a human-being perspective.
It's clear that Dave thinks that O'Reilly is 60% full of crap but, again, I don't think that's because Letterman is a subscriber to "The Nation". I think it's because Letterman sees O'Reilly as a disengenuous attack dog. He see's the lunacy of the "Fair and Balanced" claims. Again, not because he's some "crazy liberal" but, rather, because Letterman can see the obvious.