So is it possible to use backshift with the verb in the main clause and leave the other verb in the subordinate close as it is ? i.e 'I was told that my friend had had a terrible accident while he was driving to Mansoura.'
Yes, Rasha, that is not only possible but perfectly correct and normal. What would be unusual, though also correct, would be to do what you thought was needed but isn't: "I was told that my friend had had a terrible accident while he had been driving to Mansoura."
In that sentence, there are two relative tenses, "had had" and "had been driving" each being located prior to the past time of "was told." But that is totally unnecessary, because the "while"-clause is part of the reported-speech sentence and can simply expand the temporal domain of the relative tense already used.
In other words, with two instances of backshift, the sentence looks like this: "I was told [that my friend had had a terrible accident] [while he had been driving to Mansoura]." There are two relative tenses in that sentence, two temporal domains expressly located further in the past than the time of "was told."
With backshift only in the main clause of the reported speech sentence, things are not so disconnected. The sentence looks like this: "I was told [that my friend had had a terrible accident [while he was driving to Mansoura]]." "Was driving" is located inside the domain established by "had had." It expands that domain.
Thus, the answer that you and Ahmed_btm thought was wrong is really correct and normal, even though it is not incorrect to backshift twice. What educated native speakers normally do in such instances, however, if we use backshift at all, is to backshift only the main clause of the reported sentence.
The explanation I have just given you, and could go on and on about, is based not only on my experience as a native speaker but on my research, originally inspired by a historical (and historic) thread here started by my former colleague Okaasan. In the thread, a major linguist, David Crystal, weighs in on the matter:
"Jane said, 'I dropped my harmonica when/while I was swinging with Tarzan.'"