Catalans Dragons survived a strong Castleford comeback to see-off the Tigers 39-30 at the Stade Gilbert Brutus down in Perpignan.