Your database retrieve works, but in the split your comparing names (case sensitive(!)). Changing the the split to “$ObjectWithSamenName = empty” should do the trick
When I want to compare to strings to see if they’re the same, regardless of case, I end up using the string function toLowerCase()
So in your logic it would look like:
toLowerCase($ObjectWithSameName/CompanyName) != toLowerCase($Company/CompanyName)
Another option would be to put a uniqueness validation on the CompanyName field. More info on how to do that can be found here:
Hope this helps!