Miguel:
Yes you have to check the DN and if it already existed then change the ID. You will need more than just ID.
You did not mention whether you have one AD domain in your landscape or more than one.
DN = samaccountname + OU + Domain Name
Before the password CreateADUser you need to make sure you get the samaccountname and OU for the user. The domain information is given by reposity settings.
For you logic basically you are
1. Calculating user's samaccountname
2. Determine OU
3. Form DN
4. Check DN for uniqueness (If not going back to step 1 and repeat the process)
Regards
Andy