Here's the code you wanted. Instead of "dir /B" you can place any other command. Or you can use the for loop several times to append output of multiple commands in a sigle line in output file.
@echo off
setlocal enabledelayedexpansion
rem create or empty output file
echo.|set /p some=>file.txt
for /F "tokens=*" %%a in ('dir /B') do (
echo.|set /p some="%%a ">>file.txt
)