Question: I understand that Sullivan killed Barrigan at the end of the movie because there needed to be someone dead other than Costigan that Sullivan could pin as the mole in order to evade being caught. But why couldn't Sullivan keep Barrigan alive and then both of them pin Trooper Brown, who Barrigan had killed just a second beforehand, as the mole?
Answer: It is unlikely that Trooper Brown would be believable as a member of the Irish Mob, considering the fact that he is African American.
Question: What did Frank mean by the quote, "When you're looking down the barrel of a gun, what difference does it make?"
Answer: In Frank's mind, everyone is either connected to crime, or they are cops (but just as brutal and probably as corrupt as the criminals). So if it came down to being threatened with death, it doesn't matter if the guy making the threat is a civilian or a cop, he's bad either way. The line is "When I was your age, they would say you could become cops or criminals; today what I'm saying to you is this: When facing a loaded gun, what's the difference?"
Answer: At this point, Costello is dead, Queenan is dead, Billy is dead and so is Officer Brown. The only person who could tie Sullivan to Costello is Barrigan. I believe it was a matter of tying loose ends and ensuring his "fresh" start.