I am watching Gettysburg (1993) and during scene depicted in screenshot below, some infantry are walking in front of the main body of infantry. Who are these men and what are they doing? Are they dismounted cavalry or some sort of skirmishers?
They were skirmishers. While the Confederates relied on sharpshooters more than the Union did, both sides used skirmishers to detect enemy forces.
Typical tactics were to deploy about 400 meters from the reserve body, in squads of 4-5 men several paces apart. (This is what you are seeing in the image. ) Naturally, terrain affected how precisely this was followed, and in Sherman's March to the Sea the skirmishers on both sides fought almost more than the main forces.