There's so much going on wrong in your code (bad logic, missing whitespace, mismatched brackets, etc.), it's not worth the effort to try and explain why it doesn't work.
@mixin increase-specificity( $depth: 1 ) {
$sel: '';
@while($depth > 0) {
$sel: $sel + ':nth-child(n)';
$depth: $depth - 1;
}
&#{$sel} {
@content;
}
}
body {
@include increase-specificity( 2 ){
background: blue;
}
@include increase-specificity{
background: green;
}
background: red;
}