If you have limited memory space, then it is efficient usage to declare variables only within the function which uses them, because the variable ceases when the function exits, allowing memory to be released.
Another reason is in the case of a recursive function (a function which calls itself). Then you cannot use a global variable. You must create multiple versions of a variable, for each time the function calls itself.
Or suppose a different programmer is called on to make necessary revisions (because the original programmer is unavailable). The new guy might prefer to create a new function with variables unique to that function. This avoids any hassle with existing global variables, or risk of overwriting them, or any interference with them.
In most cases it might not make a difference whether you declare a variable as global, or whether you declare it only within the function which uses it.