How to use current_post to open a new unordered list every five posts

You’re basically checking ( $query->current_post + 1 ) % 5 == 0. For the last post, where $query->current_post equals 9, this also returns true, as 10 % 5 equals 0. Thus, another closing and opening of a div and a ul is outputted.

You can prevent this by checking whether there are any posts left to display (using $query->post_count, the number of posts being displayed):

if ( $query_count % 5 == 0 && $query_count < $query->post_count )