This is a great question! Much programming advice and "best practices" comes down to the question of managing complexity. Or to put it plainly: How do we write and manage a large complex program without being overwhelmed. The solution is (like with most large problems) to split it into smaller, more manageable pieces.
Each variable is a bit of complexity, but a global variable adds complexity to the whole program (because it may have effects all over the program, hence the name), while a local variable adds complexity only in a single isolated unit, the function.
The worst fear of a developer is to have a program where a change in a single function causes a totally different part of the program to fail. Each global variable increases this risk.