George Lucas was asked this question during the filming of 'Revenge of the Sith'. Suffice to say, his answer was neither illuminating, nor especially meaningful.
"So how did Anakin get that scar, George?" asks John Knoll.
"I don't know. Ask Howard," says George, referring to President of Lucas Licensing Howard Roffman. "That's one of those things that happens in the novels between the movies. I just put it there. He has to explain how it got there. I think Anakin got it slipping in the bathtub, but of course, he's not going to tell anybody that."
The book that he's referring to is 'The Rise and Fall of Darth Vader' which informs us that his scar was received during a duel with Asajj Ventress.
Lethal droids were not the only adversaries to the Jedi, as Count
Dooku had recruited such deadly beings as the Sith aspirant Asajj
Ventress and the nearly indestructible Gen'Dai bounty hunter, Durge,
to fight on his behalf. Dooku himself had trained Ventress in the art
of lightsaber combat, but often ridiculed her preference to wield two
lightsabers at the same time. Anakin nearly defeated Ventress on the
fourth moon of the gas giant Yavin. One of their duels, in the
industrial sector of Coruscant, left him with a deep scar on the right
side of his face.
The Rise and Fall of Darth Vader
We actually get to see this event in the comic serial Republic 71: Dreadnaughts of Rendili, Part 3