By the time he has written the letter, his friend will have done the shopping. By the time writes the letter, his friend will have done the shopping. To me, the first one seems more suitable if he is writing the letter now, or will be starting it soon, and it takes a reasonable time to write the letter, during which time the friend completes the shopping.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.