How does the new medication gardasil help treat HPV and cancer?

Doesn't treat it. Gardasil is a vaccine which includes strains of the virus known to cause hpv & related cervical, vaginal, anal & throat cancers.If given prior to infection, the body develops protective levels of antibodies. These antibodies will stop the germ from infecting you if exposed later. The vaccine does nothing to treat anyone after they have the germ in their system or have a related cancer.
Prevents worst HPV's. Gardasil is a 3-shot vaccine that prevents infection from 2 strains of hpv virus that cause cervical cancer, and 2 strains that cause genital warts. It also prevents anal warts (and maybe anal cancer) due to the same strains, in both men and women. The antibodies one produces from the vaccine flow in the bloodstream everywhere. Other body sites are probably protected, but this has not been proven.