third person character moves horizontally too while rotating when I just want to move it vertically

I only use W and S keys here but as you can see it also moves sideways while rotating.
8258313--1081053--movement.gif
I am using Photon Fusion here but here is my movement script:

if (networkInputData.movementInput != Vector2.zero)
{
                float _targetRotDegrees = Mathf.Atan2(networkInputData.movementInput.x, networkInputData.movementInput.y) * Mathf.Rad2Deg + networkInputData.cameraEulerAngles.y;
                float rot = Mathf.SmoothDampAngle(transform.eulerAngles.y, _targetRotDegrees, ref _rotationVelocity, RotationSmoothTime);

              
               transform.rotation = Quaternion.Euler(0.0f, rot, 0.0f);

                //Move
                Vector3 moveDirection = transform.forward * _speed;

                moveDirection.Normalize();

                networkCharacterControllerPrototypeCustom.Move(moveDirection);


}

I also checked where the pivot point was but it is in the middle.
Any idea what causes this weird rotation? Thanks!

I realised what the problem is.

It is the moveDirection. I say that it should move in the direction of transform.forward so when it is rotating, it is moving to that direction hence it moves in an arc at first.

I fixed it this way:

Vector3 moveDirection = Quaternion.Euler(0.0f, _targetRotDegrees, 0.0f) * Vector3.forward;