scap: ensure tmpfile is flushed; pass env to dsh

Change-Id: I7334667160b96f4adace08263ffc306d8dad6137