Explain why the USSR built the Berlin Wall.
First of all, let us note that it is not technically correct to say that the Soviet Union built the Berlin Wall. It was actually East Germans who built the wall. It is true that the Soviet Union had a great deal of control over East Germany and had to give its approval for the building of the wall (some historians say they ordered it to be built). But it was not the Soviets who built it.
Turning to the main part of your question, the reason for the building of the wall was the great loss of population that East Germany was experiencing. Too many of its people were simply leaving the country by going to West Berlin. This was putting a tremendous strain on the East German economy as approximately 200,000 East Germans left. This also put a strain on the Soviet economy because the East Germans were constantly appealing to the Soviets for aid. Finally, this was embarrassing to the communists as it showed that people wanted to leave their countries and go to the democratic/capitalist West.
When faced with this problem, the East German government wanted the Soviets to respond by simply taking over West Berlin. Alternatively, they wanted to be allowed to cut off all Western access to the city as had been tried during the blockade of the city in 1948-9. Khrushchev felt that these measures were too likely to result in a war. Therefore, he was not willing to do those things. However, he was willing to allow (or order) the building of the wall to prevent further escapes to the West.