How do they externalize the cost? Who is paying them? The plaintiff class-action firm pays their own costs and hopes get reimbursed when the case is resolved.
Those costs are relatively minimal, courts do charge fees (though I don't know how well that covers the court's expenses), and few class action suits go to trial - they are settled or dismissed beforehand.