According to Wikipedia, a computer file is simply a resource for storing information. The term appears to have originated in the punch card era, where a computer program was literally stored in a file (as in, a box used to store loose pages, see image below). As other forms of media were introduced, such as disks, the nomenclature followed.
From a *nix point of view, everything is a file: sockets, devices, terminals, screens/monitors, data files, pipes, and so on. Microsoft Windows, in contrast, tends to call permanent storage data "files", and volatile resources as whatever they are, such as named pipes, sockets, raster devices, etc. Other systems may have similar definitions somewhere between these two extremes.
Unfortunately, as I've just stated, there's no single definition of what a file is, because it is different things to different people, except that everyone tends to agree on the base-line definition that a file is a named resource that stores data on permanent media (permanent does not imply that it can never be modified, simply that it persists through power cycles).
(Wikipedia)