The automatic $_ variable - representing the current input object in each step of a pipeline - can only be used in arguments that are script blocks ({ ... }), not in expandable strings ("...").
A per-input-object script block is most typically used with the ForEach-Object cmdlet, but you can also use it as a delay-bind script-block parameter with pipeline-binding parameters.
While that doesn't work with Out-File, it does with Set-Content, which is generally the right tool to use with strings anyway:
(Get-ChildItem D:\Data -File -Filter *.csv).Count |
Set-Content -LiteralPath { "D:\test$_.txt" }
Note that I've replaced -Include with -Filter, which is not only more efficient, but also avoids the pitfall of
-Include only applying to the input directory path, not to the items inside it - see this GitHub issue.
Caveat: In Windows PowerShell - but fortunately no longer in PowerShell Core, where (BOM-less) UTF-8 is now consistently used - Out-File and Set-Content use different character encodings by default: UTF-16LE ("Unicode") vs. the system's active ANSI code page ("Default"); use the
-Encoding parameter to specify the desired encoding, as needed.