If you have signed in with same Apple ID and password on the same network in Mac and iPhone or other apple devices the contacts on each device will get synced , if the same contacts are in devices they will be seen as duplicates ( as if you had already created contacts in Mac and the same are in iPhone ) .
To avoid it , disconnect the desired device by just signing out from Apple ID account , then delete the duplicate contacts in each device .
Get Contacts data back on Mac ?
Take help of a web browser and enter in www.icloud.com with the apple id and password used in an iPhone , the contacts that were saved in will be visible select the desired contacts and click on gear icon in the left bottom corner and click on export as v card .
Open finder , click on downloads , right click on .vcf file and open with contacts .app( default ) .
The address book will get opened , a pop up window will appear stating are you sure you want to add number of cards , click on add .
Again open your address book the contacts that were in the iPhone will be transferred under the section “ All contacts “ in the Mac address book .
Sign out from www.icloud.com used with Apple ID and password for an iPhone .
Then enter in www.icloud.com with the apple id and password used in the Mac , click on gear icon and click on import as v card all the contacts will be transferred in the iCloud server , click on create group on the bottom right corner an untitled folder will be created in the side bar and the contacts from iOS are all transferred to the iCloud server account .
See some articles iCloud: Export a contact as a vCard from iCloud Contacts
iCloud: Import a contact into iCloud Contacts
iCloud: Create a group in iCloud Contacts
Second method https://support.apple.com/en-bw/HT205754