This use of scratch comes from a line or mark drawn or scratched into the ground to indicate a boundary or starting-point in sports, especially cricket & boxing. That meaning of scratch goes back to the late 18th century. From there it came to apply specifically to the starting point, in a handicap, of a competitor who received no odds: "Mr. Tom Sabin, of the Coventry Bicycle Club, has won, during last week, three races from scratch." (Bicycle Journal, August 18, 1878). It was later applied figuratively with the meaning "from nothing", and it was used thus by James Joyce in Ulysses (1922): "A poor foreign immigrant who started scratch as a stowaway and is now trying to turn an honest penny." Thereafter it was taking up in cooking once boxed mixes and prepared foods became available. Today it is a badge of honor to be able to say one made a culinary dish from scratch.