Conditions for generating scale-invariant density perturbations