trying to DeDuplicate using a function

trying to DeDuplicate using a function

I'm trying to write a function that will help identify duplicate records by using a primary field as a flag.

I'm not sure why the following isn't working, any thoughts?

void deDupe(date added_time, string city)
{
    pile = List:String();
    for each rec in Lead_Master  [(City = input.city && (Appointment_Date is not null))]
    {
        var = rec.Primary_Phone;
        if (pile.contains(var))
        {
            for each check in Lead_Master  [((Added_Time = input.added_time && City = input.city) && (Appointment_Date is not null))]
            {
                check.primary_record = false;
            }
        }
        pile.add(me.Primary_Phone);
    }
}