From www.word-detective.com

In any case, if you check under the entry for "scratchcake" in the Second Edition, you'll find
an explanation of "from scratch." It means, of course, from the absolute beginning, without any
advantage, in this case without benefit of a prepared soup mix. The phrase comes from the
lingo of 19th century sporting events, specifically the "scratch" drawn in the ground which
served (and often still does) as the starting line of a foot race. A runner "starting from scratch"
received no handicap or benefit -- whatever the contestant accomplished was due solely to
his or her own efforts. So, too, is a cook baking a cake without the benefit of Betty Crocker
or her ilk said to be making it "from scratch."