This use of grappling is correct. An optional rule on the Wizards of the Coast website allows you to break another's hold by making an opposed grapple check in this manner:
Break Another's Hold: This works just like breaking another's pin, except that you use it against a foe that merely has a hold on another character. If you win the opposed check, you free the character you're helping.
Grappling is the correct situation in general here, as the gelatinous cube's stats in the SRD confirm that its engulf is treated as a form of grapple:
Engulfed creatures are subject to the cube’s paralysis and acid, and are considered to be grappled and trapped within its body.
(You would, technically, have to follow all the normal rules of grappling. Since you're joining a grapple, your grab attempt automatically succeeds and doesn't provoke attacks of opportunity, but you still need to make a grapple check as a free action, which deals unarmed strike damage if successful. You can then use your next attack to break the hold, and the next attack after that to free yourself from the grapple you're now in. Also, Small creatures can't grab a gelatinous cube, which is Large.)
Strictly speaking, there's no rule that a gelatinous cube's acid harms anyone who touches it. However, the DM in this game has the right to make sensible rulings. It would also be reasonable to simplify the grapple rules to speed gameplay.