I upgraded my 3D printer to the latest Marlin firmware, while printing the first layer, the extruder moves away from the print in a straight line towards Min End Stop, sometimes in the X direction and other times in Y direction and then returns to the print and resumes printing. This strange movement doesn't happen at the same location every time. There is nothing in the Gcode that commands this move, it seems related to the firmware. I didn't have this issue with the old Marlin firmware. I'm using Arduino Mega with RAMPS 1.4.
Any help in solving this issue will be appreciated.

Thanks