How do I find the FamilyGUID of an exsting database
You can use the catalog view - sys.database_recovery_status

SELECT DB_NAME(database_id) as DatabaseName, database_guid, family_guid
FROM master.sys.database_recovery_status


You can make your restore process more sophisticated by comparing the  family_guid of the backup file and the database to be restored.

Just dump the info of RESTORE headeronly into a temp table and use above query to compare. If they are different then there is a problem.