Draco, who was a Slytherin and a bully, was trying to taunt Harry and Ron. He boasted about how he had been helping his father find the culprit, which was actually Draco himself (though he didn't know it). He then proceeded to burp up slugs, which he claimed were the result of eating a "nasty-tasting" meal.
This was a disgusting and rather comical moment in the book, highlighting Draco's immaturity and tendency towards cruelty.