Script not doing as it should half the time.

Okay so here is a script to make an object (today its a 4 x .5 x .5 cube) to track the mouse. It works half the time. As soon as the mouse goes past the 90 or 270 degree mark. The object inverts itself (I put another object at one of the cube so its pretty obvious).

I really don't want this to happen and I honestly don't understand what course to take to fix this, or if I should just look for another code altogether.

transform.LookAt(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Abs(Camera.main.transform.position.z))));

//these are just to keep it on the z-axis for since its a 2D game.
transform.rotation.y = 0;
transform.rotation.x = 0;

I don't know what exactly is happening there, but transform.rotation is Quaternion, which is a different concept than what you see in the inspector. The inspector of the Transform component shows Euler Angles. Modifying the xzyw components of a Quaternion directly is generally a bad idea.