I have to agree with the sage advice of most of the other posters - don't leave a perfectly good boat - pick up your friend, head for the shore and get some extra help to right the other boat.
That said, I have left my boat to help another cat sailor. We were both sailing solo on Galveston bay in around 15 knots of wind. He flipped just at the edge of the Houston ship channel - not a good place to be floating. Rather than do the sensible thing, I furled the jib, popped the downhaul and sheeted the main to put the boat into irons. I then lifted the rudders and hopped off my boat to swim to his. The current was against me and the wind was carrying his boat away from me - so I had to swim like hell to close what had started out as a really small gap between the boats. I was totally breathless by the time he hauled me aboard. We got his boat righted and then headed after mine - which had drifted faster downwind than the boat on it's side.
All in all not one of my smarter moves - I got away with it but wouldn't do it again unless I was in very safe water with other help to hand.
Chris.