He did it to solve a long territorial dispute between the Spanish and the Portuguese. He made the line and all territories west of the line could be taken by Spain while all territories east of the line could be taken by the Portuguese. This enabled them to stay at their own places and not cause wars or problems.