As long as $ a $ and $ b $ are both non-zero, you can let $ g $ be any non-periodic function, and let $ h $ be $ \frac 1 b ( f - a g ) $. Then $ f = a g + b h $, $ g $ and $ h $ are linearly independent, and neither $ g $ nor $ h $ is periodic.
So for example, if $ f $ is the sine function (with period $ 2 \pi $), $ a $ and $ b $ are both $ 1 $, and $ g $ is the identity function, then $ h ( x ) = \sin x - x $ for all $ x $. Now $ f = 1 g + 1 h $, $ g $ and $ h $ are linearly independent, and neither $ g $ nor $ h $ is periodic. But this example is nothing special.
However, as long as $ b $ is non-zero, if $ f $ and $ g $ are periodic (with a same period), then $ h $ must also be periodic (with that period). That's because $$ h ( x + T ) = \frac 1 b \bigl ( f ( x + T ) - a g ( x + T ) \bigr ) = \frac 1 b \bigl ( f ( x ) - a g ( x ) \bigr ) = h ( x ) \text . $$ Perhaps this is what your intuition was going for.