Categories sorting

You have orderby=count, which should be correct, but you also have order=asc. order=ASC means “smallest to largest”, at least with numbers. You want the opposite, “largest to smallest”. Use order=DESC instead. I suspect that get_terms is working, you’ve just told it something different that you actually want.

Also, you have multiple queries in a loop and no real limits on it. That could result in a huge number of database queries and a noticeable impact on server performance. Be aware.