To express surprise and delight at an unexpected happening. (An alternate usage is a long-winded of telling somebody to fuck off.)
Doug: Man I got a blow job from that really hot chick.
Fred: Wow! Scratch my balls!
Doug: Hey Fred, buy the next round of beers mate.
Fred: Scratch my balls!