The flour (along with the butter and milk) forms the roux, which is the base of the cheese sauce for the macaroni cheese. The starch in the flour helps to thicken the cheese sauce so it clings to the pasta.