He had to. He was the target of an extortion plot by some guy. This guy demanded $2 million from Letterman, or he would spill the beans about his adultery.
Letterman decided to turn the tables, not only admitting to his adultery, but contacting the police, who subsequently caught the extortionist.
Letterman and his wife have been together since 1986, though they just got married a few years ago. They have a 5 year old son together. This isn't really uncommon at that level of celebrity, but that's not justifying his actions.
I really like Letterman, and I hope this doesn't destroy his marriage. It did happen before he was married to his now wife, but when you've been together for that long, does it really matter if you were married or not?