If two users have two different documents but same name, when the second user saves his file in same document library, it overwrites the first user's document and the document gets new version. Is there any setting on library level that you can set to get a warning and prevent users to save new documents with a name that already exists.
No, no OOB settings can prevent a user from overwriting an existing document, unless you do one of the things suggested in the other answers OR you create an event receiver and attach it to your library. In this event receiver, for the itemAdding event handler, you then check if there's another document with the same name and in this case, you cancel the insertion.
On upload there is a checkbox "Overwrite current version" (or similar). This is the only setting there is.
The main problem is that this option is not given if the user drag-and-drops documents to a library view!
If users have "Contribute" permission only and if document library sets to display only users own documents, they can not overwrite documents of eachother. If they try to save a document with same name, it will give a "Permission Denied" error.