Problem is, that you rotate the object in it's local coordinates -> so the mouse localmouseposition is not what you expect.
One solution is to compare mouse_global with object's global:
mouseposition = get_global_mouse_position() - global_position;
rotation = mouseposition.angle();
set_flip_v(mouseposition.x <= 0);
The other (better) is to rotate the object within global's space:
mouseposition = get_local_mouse_position()
set_flip_v(mouseposition.x <= 0)
global_rotation += mouseposition.angle()
Generaly it's better to alter globals, not locals -> because moving object in local will affect it's collisions local_mouse and many more things.