Delete users from multisite after they have not logged in for a set amount of time?

If your code works, use it.

It ought to be possible to do this in pure SQL and that might even be more efficient, but don’t. Rather, unless you are experiencing identifiable issues using the Core code– timeouts, for example– and cannot solve them, don’t resort to a pure SQL solution.

The reason is that if the database structure or other Core functionality changes, then code based on the Core functions should (probably) survive. Code based in pure SQL might not.