Why doesn't Mayella confess the truth?
It might be difficult to be sympathetic to Mayella considering this lie costs Tom his life and perpetuates the racist tendencies of the town. She is certainly at fault for this.
But she is the victim of disadvantaged circumstances. First, her father is abusive. Second, she is raising all her siblings by herself. She essentially is her father's servant. Since the Ewell children don't go to school, the reader surmises that Mayella has no reason to leave the house. It may be the case that Tom Robinson is the only kind person that has reached out to her. Whether she mistakes Tom's kindness, takes advantage of Tom, or just reaches out for a friend - in attempting to seduce him -, and she is rebuffed, this can only add to her sense of isolation and loneliness. When she lies in court, it is to avoid the wrath of her father, and perhaps more importantly to avoid the scorn of the town andthe embarrassment of being rejected by Tom. She would be faced with a worse kind of contempt than what Atticus faced for representing Tom.