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 ?
Resolve duplicates while importing contacts into Contacts on ...support.apple.com › guide › contacts › 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 iPhone are 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
See the article If you see duplicate contacts after setting up iCloud Contacts - Apple Support (IN)
When Apple ID is signed in Mac and application contact is turned on Set up iCloud features on Mac – Apple Support (UK)
If you select duplicate contacts from Mac and delete them , automatically they will be deleted from iCloud.com
The duplicates contacts ( they will be under iCloud section > in All iCloud ) are shown in Mac address book as well as in iCloud.com if these duplicate contacts are selected from Mac address book use command and A keys and click on command and delete key they will be deleted condition they must be in series and not randomly placed , as important contacts will also be deleted .
If they are randomly placed select important contacts that are not to be deleted in on my Mac section , just select use command and A keys , copy use command and C keys and paste use command and V keys .
The duplicate contacts can also be in various groups in iCloud.com Create a group of contacts on iCloud.com - Apple Support created and they will be shown in All contacts of Mac address book ( see the first option ) .
You need to find out duplicate contacts of address book search from various groups , All contacts , All iCloud and another way is create a group name as say duplicate contacts1 find out all duplicates and club in this folder and finally delete this folder it will be removed from address book / iCloud.com
The Iphone / iPad are synced , the duplicate contacts will be deleted .