User Roles Not Sticking

You might want to use WP_User::set_role( 'contributor' ) instead. It unsets all current roles and sets the new one (the argument) too.

So the above would be

if ($count_posts >= $postlimit) {
  $current_user->set_role( 'contributor' );
}

error code: 523