In search of a last-minute birthday present for Bart, Homer wandered into a mysterious shop full of cursed items. Homer spotted the Krusty doll and figured that Bart would like it, so he bought it in spite of the shopkeeper's warning that the doll was evil. After Homer brought the doll home, it tried several times to kill him (initially unbeknownst to the rest of the family). Eventually Marge called the manufacturer for help, and a repairman came and found that the doll's Good/Evil switch was set to "Evil."
After the repairman set the doll's switch to "Good," Homer treated the doll like a personal servant (to the point of having the doll scrub his back in the bathtub). The doll found its new existence to be a chore, but enjoyed living in Lisa's dollhouse and coming home at night to Malibu Stacy.