Bloated wp_usermeta table

We have a Multisite installation using the New Blog Templates plugin. The table wp_usermeta has over 98,000 entries for only 10 sites. We have tried using the following function in the functions file with no success. add_filter('wp','cleanup');
function cleanup() {
error_log("cleanup");
global $wpdb;
$dups = $wpdb->get_results( "SELECT *, COUNT(umeta_id) AS n FROM {$wpdb->usermeta} GROUP BY user_id, meta_key HAVING n > 1");

foreach( $dups as $dup ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s AND umeta_id <> %d",
$dup->user_id, $dup->meta_key, $dup->umeta_id ) );
}
}
We can't upgrade to the newest version because we would have to upgrade hundreds of installations to make this work correctly.

Is there any way to clean duplicate entries in the wp_usermeta table without breaking the installation?