The words undo, undue sound the same but have different meanings and spellings. Why do undo, undue sound the same even though they are completely different words?
The answer is simple: undo, undue are homophones of the English language.
To reverse or erase; annul: impossible to undo the suffering caused by the war.
To untie, disassemble, or loosen: undo a shoelace.
To open (a parcel, for example); unwrap.
To cause the ruin or downfall of; destroy.
Exceeding what is appropriate or normal; excessive: "I was grateful, without showing undue excitement” ( Katherine Mansfield).
Not just, proper, or legal: undue use of force.
Not yet payable or due: an undue loan.
Definitions from The American Heritage® Dictionary of the English Language, 4th Edition and Wordnik.
Homophones (literally "same sound") are usually defined as words that share the same pronunciation, regardless of how they are spelled.