An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
IntersectWith is a mutable operation where Intersect is immutable. This means that IntersectWith modifies duplicateWith whereas Intersect will generate a new IEnumerable containing the duplicates.
If you change line 12 with this then the value that's returned from Intersect will be set back to the original variable:
duplicate = duplicate.Intersect(Family).ToHashSet();
Note that because Intersect returns an IEnumerable rather than a HashSet the .ToHashSet() call at the end will convert it.